#!/usr/bin/perl

use Test;
BEGIN { plan tests => 2 }

$basedir = $0;
$basedir =~ s|(.*)/[^/]*|$1|;

# Start the target process.
system("mkfifo $basedir/flag");
if ( ( $pid = fork() ) == 0 ) {
    exec
"runcon -t test_getpgid_target_t sh -c 'echo >$basedir/flag; while :; do :; done'";
}

# Wait for it to start.
system("read -t 5 <>$basedir/flag");

# Verify that test_getpgid_yes_t can get the target's process group ID.
$result = system "runcon -t test_getpgid_yes_t -- $basedir/source $pid 2>&1";
ok( $result, 0 );

# Verify that test_getpgid_no_t cannot get the target's process group ID.
$result = system "runcon -t test_getpgid_no_t -- $basedir/source $pid 2>&1";
ok($result);

# Kill the target
kill KILL, $pid;

# Clean up.
system "rm -f $basedir/flag";

exit;
